package fr.jcbm.client.game;

import com.maddison.gwt.logging.client.Logger;
import com.maddison.gwt.logging.client.Logging;

public class JCBMLogger {
	private static final Logger LOG = Logging.getLogger();
	
	private static JCBMLogger instance;
	
	public static JCBMLogger getInstance() {
		if(instance == null) {
			instance = new JCBMLogger();
		}
		
		return instance;
	}
	
	/**
	 * <p>Logs a message in every available console</p>
	 * 
	 * @param fullClassName : class origin of the message
	 * @param msg : message to log
	 */
	public void log(String fullClassName, String msg) {
		String simpleClassName = getSimpleClassName(fullClassName);
		String finalLogMessage = simpleClassName + " : " + msg;
		
		// LOG eclipse (dev mode)
		LOG.debug(finalLogMessage);
		
		// LOG navigateur (si possible)
		firebugLog(finalLogMessage);
	}
	
	private String getSimpleClassName(String fullClassName) {
		int firstChar = fullClassName.lastIndexOf(".") + 1;
		return fullClassName.substring(firstChar);
	}
	
	private JCBMLogger() {}
	
	
	/////////////// Code js pur
	
	private static native void firebugLog(String message) /*-{
		if(!console) return;
		
		console.log(message);
	}-*/;
	
}
